import 'dart:convert';

class Book {
  int id;
  String name;
  DateTime dateTime;
  int reviews;
  String type;
  double reviews_score;
  String link;
  String author;
  String url;
  String copyRight;
  String cover;
  String saveName;
  String introduction;
  bool publish;

  static List<Book> fromJson(dynamic data) {
    List<Book> _books = [];
    data.forEach((o) {
      var book = Book();

      book.id = o["id"];
      book.name = o['name'];
      book.dateTime = DateTime.parse(o["date_time"]);
      book.type = o["type"];
      book.reviews = o["reviews"];
      book.reviews_score = double.parse(o["reviews_score"].toString());
      book.author = o['author'];
      book.url = o["url"];
      book.introduction = o["introduction"];
      book.link = o["link"];
      book.copyRight = o["copy_right"];
      book.cover = o["cover"];
      book.saveName = o["save_name"];
      book.publish = o["publish"];

      _books.add(book);
    });
    return _books;
  }

  Book(
      {this.name,
      this.dateTime,
      this.reviews,
      this.type,
      this.reviews_score,
      this.author,
      this.url});

  @override
  String toString() {
    return 'Book{id: $id, name: $name, dateTime: $dateTime, reviews: $reviews, type: $type, reviews_score: $reviews_score, link: $link, author: $author, url: $url, copyRight: $copyRight, cover: $cover, saveName: $saveName, introduction: $introduction, publish: $publish}';
  }
}
